package com.onlyTest;

import org.apache.commons.lang3.ArrayUtils;

import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

public class clientTest {
    public static void main(String[] args) throws Exception {
        /*
        %E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20220226111923%20-%20%E5%89%AF%E6%9C%AC.png
        %E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20220226111923%20-%20%E5%89%AF%E6%9C%AC.png
        %E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20220226111923%2B%20-%20%E5%89%AF%E6%9C%AC.png
        微信图片_20220226111923 - 副本.png
        * */
        System.out.println(URLEncoder.encode("微信图片_20220226111923+ - 副本.png","UTF-8"));
        if(true) return;
        User user = new User();
        user.setName("111");
        user.setAge("222");
        Field name = user.getClass().getDeclaredField("name");
        name.setAccessible(true);
        String s = (String) name.get(user);
        System.out.println(s);
        System.out.println("=====================================");
        Integer[] arr = {0,1,2,3,4,5};
        System.out.println(findIndex(arr));
        int index = getIndex1(arr);
        System.out.println(index);
        System.out.println(3 / 2);
        System.out.println(dateTest1(new Date()));
    }
    private static Date dateTest1(Date date){
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.MONTH,instance.get(Calendar.MONTH)-1);
        return instance.getTime();
    }
    private static void dateTest(String str){
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM");
        try {
            Date parse = sd.parse(str);
            Calendar instance = Calendar.getInstance();
            instance.setTime(parse);
            instance.set(Calendar.MONTH,instance.get(Calendar.MONTH)-1);
            System.out.println(sd.format(instance.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    private static int getIndex1(Integer[] arr) {
        if(ArrayUtils.isEmpty(arr) || arr[0] != 0) return 0;
        if(arr[arr.length-1] == arr.length-1) return arr.length;
        if(arr[1] != 1) return 1;
        int length = arr.length;
        int index,max,min;
        index = (max = length-1)/2;
        min = 0;
        while (arr[index-1] != index-1 || arr[index] == index){
            if(arr[index] == index){
                int i = (max - (min = index)) / 2;
                i = (max-index)%2==0?i:i+1;
                index = i + min;
            }else{
                index = ((max = index) - min)/2 + min;
            }
        }
        ;
        return index;
    }

    public static Integer findIndex(Integer[] arr){
        Integer[] res= new Integer[99999];
        Arrays.stream(arr).forEach(item->res[item] = item);
        return ArrayUtils.indexOf(res, null);
    }
}
